﻿Ext.define('app.prm.detail.EditCost',
{
    extend: 'Ext.window.Window',
    border: true,
    title: '项目成本维护',
    width: 750,
    modal: true,
    shadow: true,
    bodyStyle: 'padding:10px',
    height: 400,
    projectId: 0,
    initComponent: function () {
        var me = this;
        // this.addEvents("savesuccess");
        this.items = [this.getForm()];
        this.buttons = [
            {
                text: '保存',
                handler: function () { this.saveCost(); }, scope: this
            },
            {
                text: '取消',
                handler: function () { this.close(); }, scope: this
            }
        ];
        me.callParent();
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.FormPanel(
            {
                border: false,
                frame: false,
                fieldDefaults: {
                    labelWidth: 160,
                    labelAlign: "right",
                    margin: 6
                },
                bodyStyle: 'padding:5px',
                items: [
                    {
                        xtype: 'container',
                        layout: 'hbox',
                        anchor: '100%',
                        items: [
                            { xtype: 'hidden', name: 'Id', value: me.projectId },
                            {
                                xtype: 'container',
                                flex: 1,
                                items: [
                                    { xtype: 'textfield', fieldLabel: '实际项目成本(￥)', name: 'actualCost' },
                                    { xtype: 'textfield', fieldLabel: '实际人工成本(￥)', name: 'actualWorkCost' },
                                    { xtype: 'textfield', fieldLabel: '实际完成量(Kg)', name: 'actualOutPut' },
                                    { xtype: 'textfield', fieldLabel: '实际原料成本(￥)', name: 'actualMaterialCost' }
                                ]
                            },
                            {
                                xtype: 'container',
                                flex: 1,
                                items: [
                                    { xtype: 'textfield', fieldLabel: '目标项目成本(￥)', name: 'targetCost' },
                                    { xtype: 'textfield', fieldLabel: '目标人工成本(￥)', name: 'targetWorkCost' },
                                    { xtype: 'textfield', fieldLabel: '目标完成量(Kg)', name: 'targetOutPut' },
                                    { xtype: 'textfield', fieldLabel: '目标原料成本(￥)', name: 'targetMaterialCost' }
                                ]
                            }
                        ]
                    }
                ]
            });
        }
        return this.form;
    },
    listeners: {
        afterrender: function (me) {
            App.AjaxGet('/api/services/app/project/Get?id=' + me.projectId, function (data) {
                me.form.getForm().setValues(data.result);
            });
        }
    },
    saveCost: function ()
    {
        var me = this;
        var form = me.form.getForm();

        App.AjaxPost('/api/services/app/project/EditCost', form.getValues(), function (data)
        {
            me.fireEvent("savesuccess", form.getValues());
        });
    }
});